/**
 * Created by Administrator on 2016/6/24.
 */
"use strict";
const sha1 = require("sha1");
const tokenConstant = require("../constants/constants").token;

/**
 * 产生出一个新的token
 * @param user
 * @param clientInfo
 * @returns {{accessToken: string, refreshToken: string, user: *, expiredTime: *, clientInfo: *}}
 */
function createToken(user) {
    const now = Date.now();
    const atSeed = user.mobile + Math.random();
    const rtSeed = user.password + Math.random();

    const accessToken = now + sha1(atSeed);
    const refreshToken = now + sha1(rtSeed);

    let token = {
        accessToken,
        refreshToken,
        user,
        expiredTime: now + tokenConstant.lifecycle,
        expired: false,
    };
    return token;
}


module.exports = {
    createToken
};
